<?php
define('ROOT_DIR', $_SERVER['DOCUMENT_ROOT'].'/');
$path = ROOT_DIR.'setting.php';
$settingsContent = file_get_contents($path);
$smtp_host = $_POST['smtp_host'];
$smtp_port = $_POST['smtp_port'];
$smtp_secure = $_POST['smtp_secure'];
$smtp_user = $_POST['smtp_user'];
$smtp_pass = $_POST['smtp_pass'];
$newSettingMailArray = <<<EOT
\$setting_mail_array = array( //邮箱配置
    'smtp_host' => '$smtp_host', //smtp服务器
    'smtp_port' => $smtp_port, //端口号,25|465
    'smtp_secure' => '$smtp_secure', //允许 TLS 或者ssl协议
    'smtp_user' => '$smtp_user', //邮箱用户
    'smtp_pass' => '$smtp_pass', //邮箱授权码
);
EOT;
$pattern = '/\$setting_mail_array = array\(.*?\);/s';
$replacement = $newSettingMailArray;
$updatedSettingsContent = preg_replace($pattern, $replacement, $settingsContent);
file_put_contents($path, $updatedSettingsContent);
echo '<script>alert("修改成功");window.location.href="../../pluginset.php?s=mail";</script>';